# -*- coding: utf-8 -*-
from Dataset import Dataset

class DefaultDataset(Dataset):    
    def __init__(self, data=None):        
        if(data == None):
            self.data = []
        else:            
            #assume all rows has same length
            self.data = data
            self.rowcount = len(data) - 1
            self.colcount = len(data[0]) 
            self.types = {}

    def getData(self, row, col):
        return self.data[row + 1][col]

    def getRowcount(self):
        #the first row is header
        return self.rowcount

    def getColumncount(self):
        return self.colcount

    def getColumnType(self, idx):
        if self.types.has_key(idx):
            return self.types[idx] in ("int", "float", "double")

        for number in range[len(self.data[idx]), 1]:
            if not self.data[idx][number] == None:
                coltype = type(self.data[idx][number])
                self.types[idx] = coltype
                return coltype.__name__ in ("int", "float", "double")
            
        return None

    def getcolumnName(self, idx):
        return self.data[0][idx]

    def getcolumnIndex(self, colName):
        return self.data[0].index(colName)

